package com.rui.study.com.rui.study.feign.hystrix;

import feign.Param;
import feign.RequestLine;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Map;

@FeignClient(name = "com.rui.study.micro.key.manage", fallback = KeyApi.KeyApiFallbacke.class)
public interface KeyApi {

    @RequestLine("GET /v1/salt?accountId={accountId}")
    Map<String, Object> getSalt(@Param("accountId") String accountId);

    @Component
    class KeyApiFallbacke implements KeyApi {

        @Override
        public Map<String, Object> getSalt(String accountId) {
            return Collections.singletonMap("hello", "world");
        }
    }

//    @Component
//    class KeyApiFallbackeFactory implements FallbackFactory<KeyApi> {
//        @Override
//        public KeyApi create(Throwable cause) {
//            return accountId -> {
//                throw new BizException(StatusCode.KEY_MANAGE_NOT_AVAILABLE);
//            };
//        }
//    }
}
